package p.ithorns.integration.transform.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;
import p.ithorns.integration.transform.entity.TranMsg;
import p.ithorns.integration.transform.mapper.TranMsgMapper;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ithorns
 * @since 2019-11-12
 */
@Service
public class TranMsgService {

    @Resource
    private TranMsgMapper mapper;

    public boolean save(TranMsg msg) {
        return mapper.insert(msg) > 0;
    }

    public boolean update(TranMsg msg) {
        UpdateWrapper<TranMsg> wrapper = new UpdateWrapper<>();
        wrapper.eq("biz_id", msg.getBizId());
        wrapper.eq("biz_type", msg.getBizType());
        return mapper.update(msg, wrapper) > 0;
    }

    public TranMsg findByBiz(String bizId, String bizType) {
        QueryWrapper<TranMsg> wrapper = new QueryWrapper<>();
        wrapper.eq("biz_id", bizId);
        wrapper.eq("biz_type", bizType);
        return  mapper.selectOne(wrapper);
    }

    public void remove(String bizId, String bizType) {
        QueryWrapper<TranMsg> wrapper = new QueryWrapper<>();
        wrapper.eq("biz_id", bizId);
        wrapper.eq("biz_type", bizType);
        mapper.delete(wrapper);
    }
}
